﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Constructor
{
    public partial class ImagePicker : Form
    {
        PictureBox _mainPB;
        public ImagePicker(PictureBox mainPB)
        {
            InitializeComponent();
            _mainPB = mainPB;
            if (External.images.LoadedImages != null)
            {
                Dictionary<string, PictureBox>.Enumerator iter = External.images.LoadedImages.GetEnumerator();
                while (iter.MoveNext())
                {
                    PictureBox pb = new PictureBox();
                    pb.BackgroundImage = iter.Current.Value.BackgroundImage;
                    pb.BackgroundImageLayout = ImageLayout.Zoom;
                    pb.Size = new Size(30, 30);
                    pb.Click += new EventHandler(pb_Click);
                    flowLayoutPanel1.Controls.Add(pb);
                }
            }
        }

        void pb_Click(object sender, EventArgs e)
        {
            _mainPB.BackgroundImage = (sender as PictureBox).BackgroundImage;
            Close();
        }

        private void ImagePicker_Leave(object sender, EventArgs e)
        {
            Close();
        }

        private void flowLayoutPanel1_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
